# Path: im-backend-master/app/schemas/conversation.py

from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional, List, Union
from .common import MessageBase, FriendBase, GroupBase


# 使用共享基础模型
class Message(MessageBase):
    pass

# 使用共享基础模型
class Friend(FriendBase):
    pass

# 使用共享基础模型
class Group(GroupBase):
    pass

# 会话项模型 (保持不变)
class ConversationItem(BaseModel):
    id: int
    roomId: int
    userId: int
    message: Message
    friend: Optional[Friend] = None
    group: Optional[Group] = None

# 获取会话列表的响应数据模型 (这个类不再直接用于 APIResponse 的 data 字段了，但保留定义)
class ConversationListResponseData(BaseModel):
    data: List[ConversationItem] = []

# 通用 API 响应模型
class APIResponse(BaseModel):
    code: int = 0
    message: str = "成功！"
    # data 可以是 List[ConversationItem] (用于 /list), ConversationItem (用于 /create), 或 None
    data: Union[List[ConversationItem], ConversationItem, None] = None # <<< 修改这里：直接包含 List[ConversationItem]

# 创建新会话的请求体模型 (保持不变)
class CreateConversationRequest(BaseModel):
    userId: int = Field(..., description="要创建会话的目标用户ID")

